<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/axios-0.18.0.js"></script>
<script type="text/javascript" src="js/vuejs-2.5.16.js"></script>
<script type="text/javascript" src="js/MyDate.js"></script>
</head>
<body>

<div id="app">
     用户：<input type="text" v-model="emp.ename"><br>
     性别:<input type="radio" v-model="emp.sex" value="男">男
      <input type="radio" v-model="emp.sex" value="女">女<br>
     生日:<input type="date" v-model="emp.birthday">  <br>
     爱好：<input type="checkbox" v-model="emp.hobbyArray" value="骑马">骑马
     <input type="checkbox" v-model="emp.hobbyArray" value="射箭">射箭
     <input type="checkbox" v-model="emp.hobbyArray" value="学习">学习<br>
     部门：<select v-model="emp.did">
        <option value="0">--请选择--</option>
        <option v-for="v in dept" :value="v.did">{{v.dname}}</option>
     </select><br>
  <input type="button" value="添加" @click="add">
</div>
<script type="text/javascript">
   var vm =new Vue({
	   el :"#app",
	   data:{
		   emp:{
			   did : 0,
			   sex : 0,
			   hobbyArray :[],
			   hobby :""
		   },
		   dept:[]
	   },
	   methods:{
		   findDept(){
				   axios.post("../findDept").then(function(response){
					   vm.dept = response.data;
				   });
		   },
		   add(){
			   console.info(this.emp.hobbyArray.length);
			   console.info(this.emp.did);
			   
			   this.emp.hobby = this.emp.hobbyArray.join(",");
			       axios.post("../add",this.emp).then(function(response){
				   var result = response.data;
				   if(result == "SUCC"){
				         location.href="toPage";
				   }else{
					    alert("添加异常");
				   }
			   }); 
		   }
	   },
	   created(){
		   this.findDept();
	   }
   });

</script>
</body>
</html>